#!/bin/bash

versionFile="include/version.h"
vision="V2.2"
hash=`git log -1 --format=%H`
commit_time=`git log -1 --format=%cd --date=local`
branch=`git name-rev --name-only HEAD`

rm -f ${versionFile}
echo "#ifndef __VERSION_H__
#define __VERSION_H__

//该文件通过 build.sh 自动生成

#include <stdio.h>
#include <iostream>

#define SOFTWARE_VERSION \"${vision}\"
#define COMMIT_HASH \"${hash}\"
#define COMMIT_TIME \"${commit_time}\"
#define GIT_REBRANCH \"${branch}\"

void version_output(int argc, char** argv)
{
  std::string tmp;
  if(argc > 1)
  {
    tmp = argv[1];
    std::string::size_type idx = tmp.find(\"--v\");
    if(idx != std::string::npos)
    {
      std::cout << \"Revision: \" << SOFTWARE_VERSION << std::endl;
      std::cout << \"Branch: \" << GIT_REBRANCH << std::endl;
      std::cout << \"Commit Hash: \" << COMMIT_HASH << std::endl;
      std::cout << \"Commit Time: \" << COMMIT_TIME << std::endl;
      std::cout << \"Build Time: \" << __DATE__ << \" \" <<__TIME__ << std::endl;
      exit(0);
    }
  }
}
#endif" >> ${versionFile}

cd ../../
catkin_make
